package com.xiaohai.wx.weather.dao;


import java.util.Date;
import java.util.List;
import org.apache.log4j.Logger;
import com.xiaohai.wx.weather.dto.Weather;
import com.xiaohai.wx.weather.service.Constants;

public class CityCacheData {
	
	private Date lastUpdatedTime ;
	
	private String index_dress_2d; //dress index in 2 days
	
	private String index_ux_2d; // 紫外线 index in 2 days
	
	private List<Weather> dataList;
	
	private int freshTime = Constants.weatherDataFreshTime; 
	
	Logger logger = Logger.getLogger(this.getClass());
	
	public CityCacheData(){
		
	}
	
	public CityCacheData(Date time, List<Weather> list){
		this.lastUpdatedTime = time;
		dataList = list;
	}
	
	public Date getLastUpdatedTime() {
		return lastUpdatedTime;
	}

	public void setLastUpdatedTime(Date lastUpdatedTime) {
		this.lastUpdatedTime = lastUpdatedTime;
	}

	public void setDataList(List<Weather> dataList) {
		this.dataList = dataList;
	}

	public List<Weather> getData(){
		return dataList;
	}
	
	public boolean isExpired(){
		
		Date now = new Date();
        // in milliseconds
        long diff = now.getTime() - lastUpdatedTime.getTime();
        long diffHours = diff / (60* 60 * 1000);
        if (diffHours > freshTime)
        {
            return true;
        }else{
        	return false;
        }
	}
	
	
	public List<Weather> getItemList(){
		return dataList;
	}

	public String getIndex_dress_2d() {
		return index_dress_2d;
	}

	public void setIndex_dress_2d(String index_dress_2d) {
		this.index_dress_2d = index_dress_2d;
	}

	public String getIndex_ux_2d() {
		return index_ux_2d;
	}

	public void setIndex_ux_2d(String index_2d) {
		this.index_ux_2d = index_2d;
	}

}
